/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package telebim;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author mejcu
 */
public class MainWindow extends JFrame {

    private JPanel[] Bottom = new JPanel[4];
    private JPanel Top;
    private JPanel Left;
    private JPanel Center;
    private JPanel Right;
    private JPanel Left_Top;
    private JPanel Left_Bottom;
    private JPanel Right_Top;
    private JPanel Right_Bottom;
    /**
     *
     */
    public Plansza plansza;
    /**
     * 
     */
    public Player[] player = new Player[4];
    private Label[] playerDescription = new Label[4];
    private BufferedImage back;

    /**
     *
     */
    public MainWindow() {
        super("Telebim");

        try {
            back = ImageIO.read(new File("src/Pic/moro.jpg"));
            player[3] = new Player("Blue", ImageIO.read(new File("src/Pic/blue.png")), ImageIO.read(new File("src/Pic/blue_skull.png")));
            player[0] = new Player("Green", ImageIO.read(new File("src/Pic/green.png")), ImageIO.read(new File("src/Pic/green_skull.png")));
            player[1] = new Player("Red", ImageIO.read(new File("src/Pic/red.png")), ImageIO.read(new File("src/Pic/red_skull.png")));
            player[2] = new Player("Yellow", ImageIO.read(new File("src/Pic/yellow.png")), ImageIO.read(new File("src/Pic/yellow_skull.png")));

        } catch (IOException ex) {
            System.out.println("Pies");
        }


        Dimension wymiar = Toolkit.getDefaultToolkit().getScreenSize();
        setSize(wymiar.width, wymiar.height);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        plansza = new Plansza();
        setLayout(new BorderLayout());
        JPanel p = new JPanel() {

            {
                setOpaque(false);
                setLayout(new BorderLayout());
            }

            @Override
            protected void paintComponent(Graphics g) {
                g.drawImage(back.getScaledInstance(getWidth(), getHeight(), 0), 0, 0, null);
                super.paintComponent(g);
            }
        };
        p.add(plansza, BorderLayout.CENTER);
        JPanel lewy = new JPanel() {

            {
                setOpaque(false);
            }
        };
        JPanel prawy = new JPanel() {

            {
                setOpaque(false);
            }
        };

        lewy.setLayout(new BorderLayout());
        lewy.add(player[0], BorderLayout.SOUTH);
        lewy.add(player[1], BorderLayout.NORTH);

        prawy.setLayout(new BorderLayout());
        prawy.add(player[2], BorderLayout.SOUTH);
        prawy.add(player[3], BorderLayout.NORTH);

        p.add(lewy, BorderLayout.WEST);
        p.add(prawy, BorderLayout.EAST);


        add(p, BorderLayout.CENTER);
        setUndecorated(true);
        setVisible(true);

        Thread painter = new Thread() {

            @Override
            public void run() {
                while (true) {
                    repaint();
                    try {
                        sleep(20);
                    } catch (InterruptedException ex) {
                        System.out.println("server sleep");
                    }
                }
            }
        };
        painter.start();
    }
}
